import { getStream } from '../Core/connect'
import * as MathUtils from '../Math/MathUtils'

type weather = 'rain' |'snow'|'sunny'|'cloud'
let ownWeather = false
export const startWeather = {
    setWeather(weatherType: weather){
        ownWeather = true
        const stream = getStream()
        const sessionId = MathUtils.generateUUID()
        const message = {setWeatherFunction: 'weatherType', type: weatherType,sessionId:sessionId}
        stream.emitUIInteraction(message)
    },
    // 设置云密度
    setCloudNum(cloudNum: number){
        if(ownWeather){
            const stream = getStream()
            const message = {setWeatherFunction: 'setCloudNum', cloudNum: cloudNum}
            stream.emitUIInteraction(message)
        }else{
            console.error('开启天气后才能更改云密度')
        }
    },
    // 设置大气高度
    setCloudHeight(cloudHeight: number){
        const stream = getStream()
        const message = {setWeatherFunction: 'setCloudHeight', cloudHeight: cloudHeight}
        stream.emitUIInteraction(message)
    },
    // 设置云速度
    setCloudSpeed(cloudSpeed: number){
        const stream = getStream()
        const message = {setWeatherFunction: 'setTimeSpeed', cloudSpeed: cloudSpeed}
        stream.emitUIInteraction(message)
    },
    // 设置云密度
    setFogNum(fogNum: number){
        if(ownWeather){
            const stream = getStream()
            const message = {setWeatherFunction: 'setFogNum', fogNum: fogNum}
            stream.emitUIInteraction(message)
        }else{
            console.error('开启天气后才能更改雾气浓度')
        }
    },
    removeWeather(){
        ownWeather = false
        const stream = getStream()
        const message = {setWeatherFunction: 'removeWeather'}
        stream.emitUIInteraction(message)
    }
}